package models;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonUnwrapped;

import play.libs.Json;

@Entity
@Table(name = "estudiante")
@NamedQuery(name = Estudiante.ESTUDIANTES, query = "SELECT e, m, a FROM Estudiante e LEFT JOIN Matricula m ON m.idEstudiante=e.id AND m.idCalendarioAcademico=:idCalendarioAcademico LEFT JOIN Acudiente a ON a.id=e.idAcudiente WHERE e.idColegio=:idColegio AND (LOWER(e.persona.nombres) LIKE :nombre "
		+ "OR LOWER(e.persona.apellidos) LIKE :nombre)")
public class Estudiante extends models.Entity<Long> {

	/**
	 * 
	 */
	public static final String ESTUDIANTES = "getEstudiantes";
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Column(name = "id_colegio")
	private Long idColegio;

	@Column(name = "id_grado")
	private Long idGrado;

	@JoinColumn(name = "id_persona")
	@OneToOne(cascade = CascadeType.PERSIST)
	@JsonUnwrapped
	private Persona persona;

	@Column(name = "id_acudiente")
	private Long idAcudiente;

	@Transient
	private Matricula matricula;

	@Transient
	private Acudiente acudiente;

	public Estudiante() {
	}

	@Override
	public Long getId() {

		return id;
	}

	@Override
	public void setId(Long id) {
		this.id = id;

	}

	public Long getIdColegio() {
		return idColegio;
	}

	public void setIdColegio(Long idColegio) {
		this.idColegio = idColegio;
	}

	public Long getIdPersona() {
		return getPersona().getId();
	}

	public void setIdPersona(Long idPersona) {

	}

	public Persona getPersona() {
		return persona;
	}

	public void setPersona(Persona persona) {
		this.persona = persona;

	}

	public Long getIdGrado() {
		return idGrado;
	}

	public void setIdGrado(Long idGrado) {
		this.idGrado = idGrado;
	}

	public String toString() {
		return Json.toJson(this).toString();
	}

	public void setMatricula(Matricula m) {
		this.matricula = m;

	}

	public Matricula getMatricula() {
		return matricula;
	}

	public Long getIdAcudiente() {
		return idAcudiente;
	}

	public void setIdAcudiente(Long idAcudiente) {
		this.idAcudiente = idAcudiente;
	}

	public Acudiente getAcudiente() {
		return acudiente;
	}

	public void setAcudiente(Acudiente acudiente) {
		this.acudiente = acudiente;
	}
}
